/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geergenbein.azw.dao.transcription;

import javax.persistence.EntityManager;
import org.geergenbein.azw.model.transcription.Dialect;
import org.geergenbein.azw.model.transcription.UntonedCodePoint;
import org.geergenbein.dao.GenericHibernateDAO;

/**
 *
 * @author andrew
 */
public class UntonedCodePointDAOHibernate extends GenericHibernateDAO<UntonedCodePoint, Long> {
    
    public UntonedCodePointDAOHibernate(EntityManager em) {
        super(em);
    }
    
    public UntonedCodePoint find(Dialect dialect, String name) {
        return (UntonedCodePoint) getSession().
                getNamedQuery("findUntonedCodePoint").
                setParameter("dialect", dialect).
                setParameter("name", name).
                uniqueResult();
    }
    
    public UntonedCodePoint loadOrPersist(Dialect dialect, String name) {
        UntonedCodePoint ucp = null;
        if ((ucp = find(dialect, name)) == null) {
            ucp = new UntonedCodePoint(dialect, name);
            makePersistent(ucp);
            log.debug("Persisted UntonedCodePoint: " + ucp);
        } else {
            log.debug("Found UntonedCodePoint: " + ucp);
        }
        return ucp;
    }
    
}
